<template>
	<view class="aplogin-view">
		<view class="vercode-login" @click="cutLogin">
			验证码登录
		</view>

		<view class="logo">
			<image src="@/static/icon/image_60.png" mode="" class="aplogin-image"></image>
		</view>

		<view class="input-all">
			<input type="text" placeholder="邮箱/手机号" class="mobile-email" v-model="userName">
			<input type="text" placeholder="请输入密码" class="password" v-model="password">
		</view>

		<view class="psw">
			<view class="" v-if="!isVerCode"></view>
			<view class="vercode-err" v-if="isVerCode">
				<image src="@/static/icon/image_20.png" class="ver-img" alt=""></image>
				账号或密码有误
			</view>
			<view class="forget-password" @click="forgetPassword">
				忘记密码？
			</view>
		</view>

		<view class="aplogin-but" @click="login">
			登录
		</view>

		<view class="login-hint">
			还没有账号？去<navigator url="/pages/register/register" class="go-login">注册</navigator>
		</view>

		<view class="login-list">
			<view class="login-item" @tap="goLogin(item.desc)" v-for="item in loginList" :key="item.imgUrl">
				<image :src="item.imgUrl" class="login-img" alt=""></image>
				{{ item.desc }}
			</view>
		</view>
	</view>
</template>

<script>
	import {
		myRequest
	} from "../../common/request.js"

	export default {
		data() {
			return {
				isVerCode: false,
				userName: "",
				password: "",
				loginList: [{
						imgUrl: "../../static/icon/image_15.png",
						desc: "Google登录",
					},
					{
						imgUrl: "../../static/icon/image_16.png",
						desc: "邮箱登录",
					},
					{
						imgUrl: "../../static/icon/image_17.png",
						desc: "微信登录",
					},
				]
			}
		},
		methods: {
			cutLogin() {
				this.$emit("cutLogin")
			},
			forgetPassword() {
				uni.navigateTo({
					url: "/pages/forgetPassword/forgetPassword"
				})
			},
			login() {
				myRequest({
						"url": "login",
						"data": {
							"username": this.userName,
							"password": this.password
						},
						"method": "post"
					})
					.then((res) => {
						console.log(res);
						uni.setStorageSync("token", res.token);
						uni.switchTab({
							url: "/pages/home/home",
						})
					})
					.catch((res) => {
						console.log(res);
					});
			},
			goLogin(desc) {
				console.log(desc);
				if (desc === "邮箱登录") {
					uni.redirectTo({
						url: "/pages/emailLogin/emailLogin",
						success(res) {
							console.log("成功");
						},
						fail(res) {
							console.log("失败", res);
						}
					})
				}
			}
		},
		onBackPress(e) {
			//e.from === 'backbutton' 说明如果点击的是物理返回键或导航栏的返回键就进行以下操作
			if (e.from === 'backbutton') {
				console.log(123);
				uni.redirectTo({ 
					url: "/pages/home/home"
				})
				return true;
			}
		},
	}
</script>

<style lang="scss" scoped>
	.aplogin-view {
		height: 100%;
		padding: 0 48rpx;
		position: relative;
	}

	.vercode-login {
		color: #FF881D;
		height: 40rpx;
		font-family: PingFang SC;
		font-weight: regular;
		font-size: 30rpx;
		line-height: 40rpx;
		letter-spacing: 0rpx;
		text-align: left;
		position: absolute;
		right: 48rpx;
	}

	.logo {
		text-align: center;

		.aplogin-image {
			margin-top: 149rpx;
			width: 170rpx;
			height: 170rpx;
		}
	}

	.input-all {
		margin-top: 99.6rpx;
		position: relative;

		.mobile-email {
			width: 100%;
			height: 56rpx;
			border-bottom: 2rpx solid #858585;
			padding: 8rpx 0;
		}

		.mobile-email::placeholder {
			color: #858585;
			font-family: PingFang SC;
			font-weight: regular;
			font-size: 30rpx;
			line-height: 40rpx;
			letter-spacing: 0rpx;
			text-align: left;
		}

		.password {
			width: 100%;
			height: 56rpx;
			border-bottom: 2rpx solid #858585;
			margin-top: 48rpx;
			padding: 8rpx 0;
		}

		.password::placeholder {
			color: #858585;
			font-family: PingFang SC;
			font-weight: regular;
			font-size: 30rpx;
			line-height: 40rpx;
			letter-spacing: 0rpx;
			text-align: left;

		}
	}

	.psw {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.vercode-err {
		color: #F44141;
		font-family: PingFang SC;
		font-weight: regular;
		font-size: 26rpx;
		letter-spacing: 0rpx;
		text-align: left;
		display: flex;
		align-items: center;
		margin-top: 12rpx;
	}

	.forget-password {
		color: #FF881D;
		font-family: PingFang SC;
		font-weight: regular;
		font-size: 26rpx;
		line-height: 40rpx;
		letter-spacing: 0rpx;
		text-align: left;
		margin-top: 12rpx;
	}

	.ver-img {
		width: 26rpx;
		height: 26rpx;
		margin-right: 18rpx;
	}

	.aplogin-but {
		height: 80rpx;
		width: 100%;
		border-radius: 20rpx;
		background: #000000;
		color: #FFFFFF;
		font-family: PingFang SC;
		font-weight: semibold;
		font-size: 28rpx;
		line-height: 80rpx;
		text-align: center;
		margin-top: 80rpx;
	}

	navigator {
		display: inline;
		font-size: 30rpx;
		color: #ff8f2b;
		border-bottom: 2rpx solid #ff8f2b;
	}

	.login-hint {
		height: 40rpx;
		color: #858585;
		font-family: PingFang SC;
		font-weight: regular;
		font-size: 30rpx;
		line-height: 40rpx;
		letter-spacing: 0rpx;
		text-align: center;
		margin-top: 32rpx;
	}

	.login-list {
		margin-top: 56rpx;
	}

	.login-item {
		height: 80rpx;
		border-radius: 20rpx;
		border: 2rpx solid #858585;
		text-align: center;
		color: #000000;
		font-family: PingFang SC;
		font-weight: medium;
		font-size: 24rpx;
		line-height: 80rpx;
		letter-spacing: 0rpx;
		margin-top: 32rpx;
		position: relative;
	}

	.login-img {
		width: 56rpx;
		height: 56rpx;
		position: absolute;
		left: 20rpx;
		top: 12rpx;
	}
</style>
